#!/bin/bash

# 奖学金排名API测试脚本
# 使用方法: ./test_ranking_api.sh

BASE_URL="http://localhost:8800"
ACADEMIC_YEAR="2022"
SCHOLARSHIP_TYPE="国家奖学金"

echo "=== 奖学金排名API测试 ==="
echo "基础URL: $BASE_URL"
echo "学年: $ACADEMIC_YEAR"
echo "奖学金类型: $SCHOLARSHIP_TYPE"
echo ""

# 测试1: 计算研二学生排名
echo "1. 计算研二学生排名..."
curl -X POST "$BASE_URL/scholarship/ranking/calculate/2?academicYear=$ACADEMIC_YEAR&scholarshipType=$SCHOLARSHIP_TYPE" \
  -H "Content-Type: application/json" \
  -w "\nHTTP状态码: %{http_code}\n\n"

# 测试2: 计算研三学生排名
echo "2. 计算研三学生排名..."
curl -X POST "$BASE_URL/scholarship/ranking/calculate/3?academicYear=$ACADEMIC_YEAR&scholarshipType=$SCHOLARSHIP_TYPE" \
  -H "Content-Type: application/json" \
  -w "\nHTTP状态码: %{http_code}\n\n"

# 测试3: 获取研二排名结果
echo "3. 获取研二排名结果..."
curl -X GET "$BASE_URL/scholarship/ranking/2?academicYear=$ACADEMIC_YEAR&scholarshipType=$SCHOLARSHIP_TYPE" \
  -H "Content-Type: application/json" \
  -w "\nHTTP状态码: %{http_code}\n\n"

# 测试4: 获取研三排名结果
echo "4. 获取研三排名结果..."
curl -X GET "$BASE_URL/scholarship/ranking/3?academicYear=$ACADEMIC_YEAR&scholarshipType=$SCHOLARSHIP_TYPE" \
  -H "Content-Type: application/json" \
  -w "\nHTTP状态码: %{http_code}\n\n"

# 测试5: 获取排名统计信息
echo "5. 获取排名统计信息..."
curl -X GET "$BASE_URL/scholarship/ranking/statistics?academicYear=$ACADEMIC_YEAR&scholarshipType=$SCHOLARSHIP_TYPE" \
  -H "Content-Type: application/json" \
  -w "\nHTTP状态码: %{http_code}\n\n"

# 测试6: 获取学生个人排名（需要替换为实际的学生ID）
echo "6. 获取学生个人排名..."
STUDENT_ID="2021001"  # 请替换为实际的学生ID
curl -X GET "$BASE_URL/scholarship/ranking/student/$STUDENT_ID?academicYear=$ACADEMIC_YEAR&scholarshipType=$SCHOLARSHIP_TYPE" \
  -H "Content-Type: application/json" \
  -w "\nHTTP状态码: %{http_code}\n\n"

# 测试7: 批量更新奖学金结果
echo "7. 批量更新奖学金结果（研二前3名获奖）..."
curl -X PUT "$BASE_URL/scholarship/ranking/update-results?academicYear=$ACADEMIC_YEAR&scholarshipType=$SCHOLARSHIP_TYPE&grade=2&topCount=3" \
  -H "Content-Type: application/json" \
  -w "\nHTTP状态码: %{http_code}\n\n"

# 测试8: 计算所有年级排名
echo "8. 计算所有年级排名..."
curl -X POST "$BASE_URL/scholarship/ranking/calculate/all?academicYear=$ACADEMIC_YEAR&scholarshipType=$SCHOLARSHIP_TYPE" \
  -H "Content-Type: application/json" \
  -w "\nHTTP状态码: %{http_code}\n\n"

echo "=== 测试完成 ==="
echo ""
echo "注意事项："
echo "1. 确保SpringBoot应用正在运行"
echo "2. 确保数据库中已执行存储过程"
echo "3. 确保有相关的测试数据"
echo "4. 根据实际情况修改STUDENT_ID" 